using UnityEngine;
using System.Collections;

public class EnemyAlertState : State<EnemyControl> 
{
	#region Singleton

    private static EnemyAlertState instance = new EnemyAlertState();
    public static EnemyAlertState Instance { get { return instance; } }
    private EnemyAlertState() { }

    #endregion

    #region State

    public override void OnEnter(EnemyControl behaviour)
    {
        behaviour.renderer.material.color = Color.red;
        behaviour.player.EnemyAlertEnter();
    }

    public override void OnUpdate(EnemyControl behaviour)
    {
        behaviour.MoveTo(behaviour.player.transform.position, behaviour.runSpeed);

        if (!behaviour.IsPlayerInRayRange())
        {
            behaviour.playerLastLocation = behaviour.player.transform.position;
            behaviour.probSearch = behaviour.probSearchFromAlert.NextValue();
            behaviour.State = EnemyCheckState.Instance;
        }
    }

    public override void OnExit(EnemyControl behaviour)
    {
        behaviour.Controller.ResetPath();
        behaviour.player.EnemyAlertExit();
    }

    public override void OnAction(string name, EnemyControl behaviour, object value)
    {
    }

    #endregion
}
